<#assign menu="classes">
<#assign submenu="classes_add">
<#include "/system/head.ftl">
<style type="text/css">
.m-bot15 {
    margin-bottom: 5px;
}
.form-control {
    border: 1px solid #E2E2E4;
    box-shadow: none;
    color: #C2C2C2;
}
.input-lg {
    border-radius: 6px;
    font-size: 15px;
    height: 40px;
    line-height: 1.33;
    padding: 9px 15px；
}

</style>
		<!--main content start-->
		<section id="main-content">
			<section class="wrapper">
              <!-- page start-->
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                            	 添加栏目
                          </header>
                          <div class="panel-body">
                              <form id="add_classesEntity_form" method="post" class="form-horizontal" autocomplete="off" action="${basePath}/admin/classes/addNew.json">
                              	<fieldset>
                                  <div class="form-group">
                                      <label class="col-sm-2 col-sm-2 control-label">栏目名称</label>
                                      <div class="col-sm-10">
                                          <input type="text" class="form-control" name="classesEntity.name"
                                          	placeholder="栏目名称" id="name" value="<#if name??>${name}</#if>">
                                      </div>
                                  </div>
                                  <div class="form-group">
                                      <label class="col-sm-2 col-sm-2 control-label">栏目别名</label>
                                      <div class="col-sm-10">
                                          <input type="text" class="form-control" name="classesEntity.aliasName"
                                          	placeholder="栏目别名" id="aliasName" value="<#if aliasName??>${aliasName}</#if>">
                                      </div>
                                  </div>
                                  <div class="form-group">
                                      <label class="col-sm-2 col-sm-2 control-label">栏目类型</label>
                                      <div class="col-sm-10">
										<select class="form-control input-lg m-bot15" style="font-size:15px;width: 300px;" id="type" name="classesEntity.type" onChange=checkType(this.value)>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="article" selected>文章</option>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="video">视频</option>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="picture">图文</option>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="single">单页</option>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="down">下载</option>
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="otherUrl">外链</option>
			                            </select>                                        
                                      </div>
                                  </div> 
                                  <div class="form-group" id="fatherId_div">
                                      <label class="col-sm-2 col-sm-2 control-label">栏目上级</label>
                                     <div class="col-sm-10">
										<select class="form-control input-lg m-bot15" style="font-size:15px;width: 300px;" id="fatherId" name="classesEntity.fatherId">
					                        <option style="background-color:#DFF0D8;font-weight:bold;" value="0" selected>做为一级栏目</option>
			                            </select>                                        
                                      </div>
                                  </div>
                                  
                                  <div class="form-group" style="display:none;" id="outUrl_div">
                                      <label class="col-sm-2 col-sm-2 control-label">栏目外链</label>
                                      <div class="col-sm-10">
                                          <input type="text" class="form-control" name="classesEntity.outUrl"
                                          	placeholder="栏目外链，类型为外链时有效" id="outUrl" value="<#if outUrl??>${outUrl}</#if>">
                                      </div>
                                  </div>
                                  <div class="form-group" style="display:none;">
                                      <label class="col-sm-2 col-sm-2 control-label">作者</label>
                                      <div class="col-sm-10">
                                          <input type="text" class="form-control" name="classesEntity.authorName"
                                          	placeholder="作者" id="authorName" value="<#if SESSION_ADMIN??>${SESSION_ADMIN.name}</#if>">
                                      </div>
                                  </div>
                                  
                                  <div class="form-group">
                                  	<label class="col-sm-2 col-sm-2 control-label"></label>
                                      <button class="btn btn-danger" type="submit">增加</button>
                                  </div>
                                 </fieldset>
                              </form>
                          </div>
                      </section>
                  </div>
              </div>
              <!-- page end-->
          </section>
		</section>
		<!--main content end-->
<script type="text/javascript">
	$(function() {
		$('#add_classesEntity_form').ajaxForm({
			dataType : 'json',
			success : function(data) {
				if (data.result) {
					bootbox.alert("保存成功，将刷新页面", function() {
						window.location.reload();
					});
				}else{
					showErrors($('#add_classesEntity_form'),data.errors);
				}
			},
			error:function(data,textstatus){
		        bootbox.alert({  
		            buttons: {  
		               ok: {  
		                    label: '关闭'
		               }  
		            },
		            message: data.responseText,
		            title: '<@spring.message "system.errorTip"/>',  
		        });
	        }  
		});
	});	
	$(document).ready(function(){ 
	   checkType("article");
	}); 
function checkType(type){
	if(type=="otherUrl"){
		$("#outUrl_div").show();
		$("#fatherId_div").hide();
		$("#fatherId").html("");
		$("#fatherId").append("<option style='background-color:#DFF0D8;font-weight:bold;' value='0' selected>做为一级栏目</option>");
	}else{
		$("#fatherId_div").show();
		$("#outUrl_div").hide();
		//获取可以选择的父级
		$.ajax({
			url: '/admin/classes/getClassesByType.json',
			type: 'POST',
			data:{"type":type},
			dataType: 'json',
			timeout: 5000,
			error: function(){
				 bootbox.alert({  
		            buttons: {  
		               ok: {  
		                    label: '关闭'
		               }  
		            },
		            message: data.responseText,
		            title: '<@spring.message "system.errorTip"/>',  
		        });
			},
			success: function(data){
				$("#fatherId").html("");
				if (data.result) {
					$("#fatherId").append("<option style='background-color:#DFF0D8;font-weight:bold;' value='0' selected>做为一级栏目</option>");
					var list=data.t;
					for(var i=0;i<list.length;i++){
						$("#fatherId").append("<option style='background-color:#DFF0D8;font-weight:bold;' value='"+list[i].id+"'>"+list[i].name+"</option>");
					}
				}else{
					showErrors($('#add_classesEntity_form'),data.errors);
				}
			}
		});
	}
}
</script>
<#include "/system/foot.ftl">
